/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaPrincipal.java
 *
 * Created on 05/09/2012, 11:16:38
 */
package GUI;

import br.ufrn.dca.controle.QuanserClientException;
import controle.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;

/**
 *
 * @author Lindemberg
 */
public class JanelaPrincipal extends javax.swing.JFrame {
    
    private Grafico plotando;
    private int largura, altura, portaSaida, portaEntrada;
    private double temporizador, tensao, erro, nivelT1,offset;
    private double sinal_lido;
    private Timer t;

    /** Creates new form JanelaPrincipal */
    public JanelaPrincipal() {
        initComponents();
        addBotoesNoGrupo();
        
        controlador = new Controlador();
        jtLog.setText(controlador.getLog());
        jxCollapse.setCollapsed(true);
        jxCollapse.setAnimated(true);
        //jbToogle.setAction(jxCollapse.getActionMap().get("toggle"));
        temporizador = 0.0;

        inicializar();
        
        largura = jPanel1.getWidth();
        altura = jPanel1.getHeight();
        setExtendedState(MAXIMIZED_BOTH);
        plotando = Grafico.getInstance(largura+350, altura);//new Grafico("Gráfico", largura, altura);
        iniciarPlot();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        group = new javax.swing.ButtonGroup();
        barraDeFerramentas = new javax.swing.JToolBar();
        jLabel1 = new javax.swing.JLabel();
        jbConectar = new javax.swing.JButton();
        jbDesconectar = new javax.swing.JButton();
        jbToogle = new javax.swing.JButton();
        jxCollapse = new org.jdesktop.swingx.JXCollapsiblePane();
        jp1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jrb0 = new javax.swing.JRadioButton();
        jrb1 = new javax.swing.JRadioButton();
        jrb2 = new javax.swing.JRadioButton();
        jrb3 = new javax.swing.JRadioButton();
        jrb4 = new javax.swing.JRadioButton();
        jrb5 = new javax.swing.JRadioButton();
        jrb6 = new javax.swing.JRadioButton();
        jrb7 = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jrbe0 = new javax.swing.JRadioButton();
        jrbe1 = new javax.swing.JRadioButton();
        jrbe2 = new javax.swing.JRadioButton();
        jrbe3 = new javax.swing.JRadioButton();
        jrbe4 = new javax.swing.JRadioButton();
        jrbe5 = new javax.swing.JRadioButton();
        jrbe6 = new javax.swing.JRadioButton();
        jrbe7 = new javax.swing.JRadioButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        jtServidor = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jcbPorta = new javax.swing.JComboBox();
        jSeparator2 = new javax.swing.JSeparator();
        jrbMalhaAberta = new javax.swing.JRadioButton();
        jrbMalhaFechada = new javax.swing.JRadioButton();
        jLabel6 = new javax.swing.JLabel();
        jcbSinal = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jtSP = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        amplitude = new javax.swing.JSpinner();
        jLabel11 = new javax.swing.JLabel();
        jtOffSet = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jcbControladores = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        kp = new javax.swing.JTextField();
        ki = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        kd = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtLog = new javax.swing.JTextArea();
        jlsp = new javax.swing.JLabel();
        jlt1 = new javax.swing.JLabel();
        jlt2 = new javax.swing.JLabel();
        jlerro = new javax.swing.JLabel();
        jltensao = new javax.swing.JLabel();
        jltemp = new javax.swing.JLabel();
        jlamplitude = new javax.swing.JLabel();
        BarraDeMenus = new javax.swing.JMenuBar();
        MenuArquivo = new javax.swing.JMenu();
        jmConectar = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        MenuConfiguracao = new javax.swing.JMenu();
        MenuSaidas = new javax.swing.JMenu();
        s0 = new javax.swing.JCheckBoxMenuItem();
        s1 = new javax.swing.JCheckBoxMenuItem();
        s2 = new javax.swing.JCheckBoxMenuItem();
        s3 = new javax.swing.JCheckBoxMenuItem();
        s4 = new javax.swing.JCheckBoxMenuItem();
        s5 = new javax.swing.JCheckBoxMenuItem();
        s6 = new javax.swing.JCheckBoxMenuItem();
        s7 = new javax.swing.JCheckBoxMenuItem();
        MenuEntradas = new javax.swing.JMenu();
        e0 = new javax.swing.JCheckBoxMenuItem();
        e1 = new javax.swing.JCheckBoxMenuItem();
        e2 = new javax.swing.JCheckBoxMenuItem();
        e3 = new javax.swing.JCheckBoxMenuItem();
        e4 = new javax.swing.JCheckBoxMenuItem();
        e5 = new javax.swing.JCheckBoxMenuItem();
        e6 = new javax.swing.JCheckBoxMenuItem();
        e7 = new javax.swing.JCheckBoxMenuItem();
        MenuPortas = new javax.swing.JMenu();
        p1 = new javax.swing.JCheckBoxMenuItem();
        p2 = new javax.swing.JCheckBoxMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        barraDeFerramentas.setFloatable(false);
        barraDeFerramentas.setRollover(true);

        jLabel1.setText("   Conexão");
        barraDeFerramentas.add(jLabel1);

        jbConectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/greenBall.png"))); // NOI18N
        jbConectar.setFocusable(false);
        jbConectar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbConectar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbConectarActionPerformed(evt);
            }
        });
        barraDeFerramentas.add(jbConectar);

        jbDesconectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/redBall.png"))); // NOI18N
        jbDesconectar.setFocusable(false);
        jbDesconectar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbDesconectar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbDesconectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbDesconectarActionPerformed(evt);
            }
        });
        barraDeFerramentas.add(jbDesconectar);

        jbToogle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/config.png"))); // NOI18N
        jbToogle.setFocusable(false);
        jbToogle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbToogle.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbToogle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbToogleActionPerformed(evt);
            }
        });
        barraDeFerramentas.add(jbToogle);

        jLabel2.setText("Saídas analógicas:");

        jrb0.setText("0");
        jrb0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb0ActionPerformed(evt);
            }
        });

        jrb1.setText("1");
        jrb1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb1ActionPerformed(evt);
            }
        });

        jrb2.setText("2");
        jrb2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb2ActionPerformed(evt);
            }
        });

        jrb3.setText("3");
        jrb3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb3ActionPerformed(evt);
            }
        });

        jrb4.setText("4");
        jrb4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb4ActionPerformed(evt);
            }
        });

        jrb5.setText("5");
        jrb5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb5ActionPerformed(evt);
            }
        });

        jrb6.setText("6");
        jrb6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb6ActionPerformed(evt);
            }
        });

        jrb7.setText("7");
        jrb7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb7ActionPerformed(evt);
            }
        });

        jLabel3.setText("Entradas analógicas:");

        jrbe0.setText("0");
        jrbe0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe0ActionPerformed(evt);
            }
        });

        jrbe1.setText("1");
        jrbe1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe1ActionPerformed(evt);
            }
        });

        jrbe2.setText("2");
        jrbe2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe2ActionPerformed(evt);
            }
        });

        jrbe3.setText("3");
        jrbe3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe3ActionPerformed(evt);
            }
        });

        jrbe4.setText("4");
        jrbe4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe4ActionPerformed(evt);
            }
        });

        jrbe5.setText("5");
        jrbe5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe5ActionPerformed(evt);
            }
        });

        jrbe6.setText("6");
        jrbe6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe6ActionPerformed(evt);
            }
        });

        jrbe7.setText("7");
        jrbe7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbe7ActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel4.setText("IP:");

        jtServidor.setText("10.13.99.69");

        jLabel5.setText("Porta:");

        jcbPorta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "20081", "20082" }));
        jcbPorta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPortaActionPerformed(evt);
            }
        });

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jrbMalhaAberta.setText("Malha aberta");
        jrbMalhaAberta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbMalhaAbertaActionPerformed(evt);
            }
        });

        jrbMalhaFechada.setText("Malha fechada");
        jrbMalhaFechada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbMalhaFechadaActionPerformed(evt);
            }
        });

        jLabel6.setText("Sinal:");

        jcbSinal.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Degrau", "Senoidal", "Quadrada", "Dente de serra", "Aleatório" }));

        jLabel7.setText("Set-point:");

        jtSP.setText("20");

        jLabel8.setText("cm");

        jLabel9.setText("Amplitude:");

        jLabel10.setText("Volts");

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jButton1.setText("Aplicar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        amplitude.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(1.6f), Float.valueOf(0.0f), Float.valueOf(3.0f), Float.valueOf(0.1f)));
        amplitude.setPreferredSize(new java.awt.Dimension(240, 240));

        jLabel11.setText("Off-set");

        jtOffSet.setText("0");

        jLabel12.setText("Controladores");

        jcbControladores.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nenhum", "P", "PI", "PD", "PID", "PI-D" }));

        jLabel13.setText("K p");

        kp.setText("2");

        ki.setText("0.5");

        jLabel14.setText("K i");

        kd.setText("0.05");

        jLabel15.setText("K d");

        javax.swing.GroupLayout jp1Layout = new javax.swing.GroupLayout(jp1);
        jp1.setLayout(jp1Layout);
        jp1Layout.setHorizontalGroup(
            jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jp1Layout.createSequentialGroup()
                                .addComponent(jrb4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb7))
                            .addGroup(jp1Layout.createSequentialGroup()
                                .addComponent(jrb0)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrb3))))
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jp1Layout.createSequentialGroup()
                                .addComponent(jrbe4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe7))
                            .addGroup(jp1Layout.createSequentialGroup()
                                .addComponent(jrbe0)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jrbe3)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtServidor, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbPorta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jrbMalhaAberta)
                    .addComponent(jrbMalhaFechada, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(31, 31, 31)
                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbSinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(amplitude, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10))
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtSP, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtOffSet, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbControladores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(kp, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ki, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(kd, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(346, 346, 346))
        );
        jp1Layout.setVerticalGroup(
            jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator3)
                    .addComponent(jSeparator2)
                    .addComponent(jSeparator1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jp1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jrbMalhaAberta)
                            .addComponent(jLabel6)
                            .addComponent(jcbSinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jrbMalhaFechada)
                            .addComponent(jLabel7)
                            .addComponent(jtSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(jLabel11)
                            .addComponent(jtOffSet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel9)
                                .addComponent(jLabel10)
                                .addComponent(amplitude, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jButton1)))
                    .addGroup(jp1Layout.createSequentialGroup()
                        .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jp1Layout.createSequentialGroup()
                                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel12)
                                    .addComponent(jcbControladores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel13)
                                    .addComponent(kp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel14)
                                    .addComponent(ki, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel15)
                                    .addComponent(kd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jp1Layout.createSequentialGroup()
                                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel4)
                                    .addComponent(jtServidor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel5)
                                    .addComponent(jcbPorta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jp1Layout.createSequentialGroup()
                                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jp1Layout.createSequentialGroup()
                                        .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jrb0)
                                            .addComponent(jrb1)
                                            .addComponent(jrb2)
                                            .addComponent(jrb3))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jrb4)
                                            .addComponent(jrb5)
                                            .addComponent(jrb6)
                                            .addComponent(jrb7))))
                                .addGap(3, 3, 3)
                                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel3)
                                    .addComponent(jrbe0)
                                    .addComponent(jrbe1)
                                    .addComponent(jrbe2)
                                    .addComponent(jrbe3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jrbe4)
                                    .addComponent(jrbe5)
                                    .addComponent(jrbe6)
                                    .addComponent(jrbe7))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jxCollapse.getContentPane().add(jp1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1139, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 385, Short.MAX_VALUE)
        );

        jtLog.setColumns(20);
        jtLog.setRows(5);
        jScrollPane1.setViewportView(jtLog);

        jTabbedPane1.addTab("output", jScrollPane1);

        jlsp.setText("Set-point:");

        jlt1.setText("Nível T1:");

        jlt2.setText("Nível T2:");

        jlerro.setText("Erro:");

        jltensao.setText("Tensão:");

        jltemp.setText("Temporizador:");

        jlamplitude.setText("Amplitude:");

        MenuArquivo.setText("Arquivo");

        jmConectar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jmConectar.setText("Conectar");
        jmConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmConectarActionPerformed(evt);
            }
        });
        MenuArquivo.add(jmConectar);

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Desconectar");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        MenuArquivo.add(jMenuItem1);

        BarraDeMenus.add(MenuArquivo);

        MenuConfiguracao.setText("Configuração");

        MenuSaidas.setText("Saídas analógicas");

        s0.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_0, java.awt.event.InputEvent.CTRL_MASK));
        s0.setSelected(true);
        s0.setText("Saída analógica 0");
        s0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s0ActionPerformed(evt);
            }
        });
        MenuSaidas.add(s0);

        s1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.CTRL_MASK));
        s1.setSelected(true);
        s1.setText("Saída analógica 1");
        s1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s1ActionPerformed(evt);
            }
        });
        MenuSaidas.add(s1);

        s2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_2, java.awt.event.InputEvent.CTRL_MASK));
        s2.setSelected(true);
        s2.setText("Saída analógica 2");
        s2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s2ActionPerformed(evt);
            }
        });
        MenuSaidas.add(s2);

        s3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_3, java.awt.event.InputEvent.CTRL_MASK));
        s3.setSelected(true);
        s3.setText("Saída analógica 3");
        s3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s3ActionPerformed(evt);
            }
        });
        MenuSaidas.add(s3);

        s4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_4, java.awt.event.InputEvent.CTRL_MASK));
        s4.setSelected(true);
        s4.setText("Saída analógica 4");
        s4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s4ActionPerformed(evt);
            }
        });
        MenuSaidas.add(s4);

        s5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_5, java.awt.event.InputEvent.CTRL_MASK));
        s5.setSelected(true);
        s5.setText("Saída analógica 5");
        s5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s5ActionPerformed(evt);
            }
        });
        MenuSaidas.add(s5);

        s6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_6, java.awt.event.InputEvent.CTRL_MASK));
        s6.setSelected(true);
        s6.setText("Saída analógica 6");
        s6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s6ActionPerformed(evt);
            }
        });
        MenuSaidas.add(s6);

        s7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_7, java.awt.event.InputEvent.CTRL_MASK));
        s7.setSelected(true);
        s7.setText("Saída analógica 7");
        s7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                s7ActionPerformed(evt);
            }
        });
        MenuSaidas.add(s7);

        MenuConfiguracao.add(MenuSaidas);

        MenuEntradas.setText("Entradas analógicas");

        e0.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_0, java.awt.event.InputEvent.ALT_MASK));
        e0.setSelected(true);
        e0.setText("Entrada analógica 0");
        e0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e0ActionPerformed(evt);
            }
        });
        MenuEntradas.add(e0);

        e1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.ALT_MASK));
        e1.setSelected(true);
        e1.setText("Entrada analógica 1");
        e1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e1ActionPerformed(evt);
            }
        });
        MenuEntradas.add(e1);

        e2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_2, java.awt.event.InputEvent.ALT_MASK));
        e2.setSelected(true);
        e2.setText("Entrada analógica 2");
        e2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e2ActionPerformed(evt);
            }
        });
        MenuEntradas.add(e2);

        e3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_3, java.awt.event.InputEvent.ALT_MASK));
        e3.setSelected(true);
        e3.setText("Entrada analógica 3");
        e3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e3ActionPerformed(evt);
            }
        });
        MenuEntradas.add(e3);

        e4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_4, java.awt.event.InputEvent.ALT_MASK));
        e4.setSelected(true);
        e4.setText("Entrada analógica 4");
        e4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e4ActionPerformed(evt);
            }
        });
        MenuEntradas.add(e4);

        e5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_5, java.awt.event.InputEvent.ALT_MASK));
        e5.setSelected(true);
        e5.setText("Entrada analógica 5");
        e5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e5ActionPerformed(evt);
            }
        });
        MenuEntradas.add(e5);

        e6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_6, java.awt.event.InputEvent.ALT_MASK));
        e6.setSelected(true);
        e6.setText("Entrada analógica 6");
        e6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e6ActionPerformed(evt);
            }
        });
        MenuEntradas.add(e6);

        e7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_7, java.awt.event.InputEvent.ALT_MASK));
        e7.setSelected(true);
        e7.setText("Entrada analógica 7");
        e7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                e7ActionPerformed(evt);
            }
        });
        MenuEntradas.add(e7);

        MenuConfiguracao.add(MenuEntradas);

        MenuPortas.setText("Portas");

        p1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.SHIFT_MASK));
        p1.setSelected(true);
        p1.setText("Porta 20081");
        p1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                p1ActionPerformed(evt);
            }
        });
        MenuPortas.add(p1);

        p2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_2, java.awt.event.InputEvent.SHIFT_MASK));
        p2.setSelected(true);
        p2.setText("Porta 20082");
        p2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                p2ActionPerformed(evt);
            }
        });
        MenuPortas.add(p2);

        MenuConfiguracao.add(MenuPortas);

        BarraDeMenus.add(MenuConfiguracao);

        setJMenuBar(BarraDeMenus);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(barraDeFerramentas, javax.swing.GroupLayout.DEFAULT_SIZE, 1159, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jxCollapse, javax.swing.GroupLayout.PREFERRED_SIZE, 1139, Short.MAX_VALUE)
                .addGap(10, 10, 10))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1139, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlsp)
                .addGap(52, 52, 52)
                .addComponent(jlt1)
                .addGap(57, 57, 57)
                .addComponent(jlt2)
                .addGap(46, 46, 46)
                .addComponent(jlerro)
                .addGap(58, 58, 58)
                .addComponent(jltensao)
                .addGap(51, 51, 51)
                .addComponent(jltemp)
                .addGap(58, 58, 58)
                .addComponent(jlamplitude)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(barraDeFerramentas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxCollapse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlsp)
                    .addComponent(jlt1)
                    .addComponent(jlt2)
                    .addComponent(jlerro)
                    .addComponent(jltensao)
                    .addComponent(jltemp)
                    .addComponent(jlamplitude))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbConectarActionPerformed
        conectar();
    }//GEN-LAST:event_jbConectarActionPerformed

    private void jbDesconectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbDesconectarActionPerformed
        t.stop();
    }//GEN-LAST:event_jbDesconectarActionPerformed

    private void jbToogleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbToogleActionPerformed
        if(jxCollapse.isCollapsed()){
            jxCollapse.setCollapsed(false);
        }else{
            jxCollapse.setCollapsed(true);
        }
    }//GEN-LAST:event_jbToogleActionPerformed

    private void s0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s0ActionPerformed
        setSaida(0, s0.isSelected());
    }//GEN-LAST:event_s0ActionPerformed

    private void s1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s1ActionPerformed
        setSaida(1, s1.isSelected());
    }//GEN-LAST:event_s1ActionPerformed

    private void s2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s2ActionPerformed
        setSaida(2, s2.isSelected());
    }//GEN-LAST:event_s2ActionPerformed

    private void s3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s3ActionPerformed
        setSaida(3, s3.isSelected());
    }//GEN-LAST:event_s3ActionPerformed

    private void s4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s4ActionPerformed
        setSaida(4, s4.isSelected());
    }//GEN-LAST:event_s4ActionPerformed

    private void s5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s5ActionPerformed
        setSaida(5, s5.isSelected());
    }//GEN-LAST:event_s5ActionPerformed

    private void s6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s6ActionPerformed
        setSaida(6, s6.isSelected());
    }//GEN-LAST:event_s6ActionPerformed

    private void s7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s7ActionPerformed
        setSaida(7, s7.isSelected());
    }//GEN-LAST:event_s7ActionPerformed

    private void e0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e0ActionPerformed
        setEntrada(0);
    }//GEN-LAST:event_e0ActionPerformed

    private void e1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e1ActionPerformed
        setEntrada(1);
    }//GEN-LAST:event_e1ActionPerformed

    private void e2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e2ActionPerformed
        setEntrada(2);
    }//GEN-LAST:event_e2ActionPerformed

    private void e3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e3ActionPerformed
        setEntrada(3);
    }//GEN-LAST:event_e3ActionPerformed

    private void e4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e4ActionPerformed
        setEntrada(4);
    }//GEN-LAST:event_e4ActionPerformed

    private void e5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e5ActionPerformed
        setEntrada(5);
    }//GEN-LAST:event_e5ActionPerformed

    private void e6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e6ActionPerformed
        setEntrada(6);
    }//GEN-LAST:event_e6ActionPerformed

    private void e7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_e7ActionPerformed
        setEntrada(7);
    }//GEN-LAST:event_e7ActionPerformed

    private void p1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_p1ActionPerformed
        setPorta(20081);
    }//GEN-LAST:event_p1ActionPerformed

    private void p2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_p2ActionPerformed
        setPorta(20082);
    }//GEN-LAST:event_p2ActionPerformed

    private void jrb0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb0ActionPerformed
        setSaida(0, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb0ActionPerformed

    private void jrb1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb1ActionPerformed
        setSaida(1, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb1ActionPerformed

    private void jrb2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb2ActionPerformed
        setSaida(2, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb2ActionPerformed

    private void jrb3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb3ActionPerformed
        setSaida(3, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb3ActionPerformed

    private void jrb4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb4ActionPerformed
        setSaida(4, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb4ActionPerformed

    private void jrb5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb5ActionPerformed
        setSaida(5, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb5ActionPerformed

    private void jrb6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb6ActionPerformed
        setSaida(6, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb6ActionPerformed

    private void jrb7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb7ActionPerformed
        setSaida(7, ((JRadioButton)evt.getSource()).isSelected());
    }//GEN-LAST:event_jrb7ActionPerformed

    private void jrbe0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe0ActionPerformed
        setEntrada(0);
    }//GEN-LAST:event_jrbe0ActionPerformed

    private void jrbe1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe1ActionPerformed
        setEntrada(1);
    }//GEN-LAST:event_jrbe1ActionPerformed

    private void jrbe2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe2ActionPerformed
        setEntrada(2);
    }//GEN-LAST:event_jrbe2ActionPerformed

    private void jrbe3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe3ActionPerformed
        setEntrada(3);
    }//GEN-LAST:event_jrbe3ActionPerformed

    private void jrbe4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe4ActionPerformed
        setEntrada(4);
    }//GEN-LAST:event_jrbe4ActionPerformed

    private void jrbe5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe5ActionPerformed
        setEntrada(5);
    }//GEN-LAST:event_jrbe5ActionPerformed

    private void jrbe6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe6ActionPerformed
        setEntrada(6);
    }//GEN-LAST:event_jrbe6ActionPerformed

    private void jrbe7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbe7ActionPerformed
        setEntrada(7);
    }//GEN-LAST:event_jrbe7ActionPerformed

    private void jrbMalhaAbertaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbMalhaAbertaActionPerformed
        setMalha(Malha.ABERTA);
    }//GEN-LAST:event_jrbMalhaAbertaActionPerformed

    private void jrbMalhaFechadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbMalhaFechadaActionPerformed
        setMalha(Malha.FECHADA);
    }//GEN-LAST:event_jrbMalhaFechadaActionPerformed

    private void jcbPortaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPortaActionPerformed
        if(jcbPorta.getSelectedIndex() == 0){
            setPorta(20081);
        }else{
            setPorta(20082);
        }
    }//GEN-LAST:event_jcbPortaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        setDadosMalhas();
        setServidor(jtServidor.getText());
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jmConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmConectarActionPerformed
        conectar();
    }//GEN-LAST:event_jmConectarActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        t.stop();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new JanelaPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar BarraDeMenus;
    private javax.swing.JMenu MenuArquivo;
    private javax.swing.JMenu MenuConfiguracao;
    private javax.swing.JMenu MenuEntradas;
    private javax.swing.JMenu MenuPortas;
    private javax.swing.JMenu MenuSaidas;
    private javax.swing.JSpinner amplitude;
    private javax.swing.JToolBar barraDeFerramentas;
    private javax.swing.JCheckBoxMenuItem e0;
    private javax.swing.JCheckBoxMenuItem e1;
    private javax.swing.JCheckBoxMenuItem e2;
    private javax.swing.JCheckBoxMenuItem e3;
    private javax.swing.JCheckBoxMenuItem e4;
    private javax.swing.JCheckBoxMenuItem e5;
    private javax.swing.JCheckBoxMenuItem e6;
    private javax.swing.JCheckBoxMenuItem e7;
    private javax.swing.ButtonGroup group;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton jbConectar;
    private javax.swing.JButton jbDesconectar;
    private javax.swing.JButton jbToogle;
    private javax.swing.JComboBox jcbControladores;
    private javax.swing.JComboBox jcbPorta;
    private javax.swing.JComboBox jcbSinal;
    private javax.swing.JLabel jlamplitude;
    private javax.swing.JLabel jlerro;
    private javax.swing.JLabel jlsp;
    private javax.swing.JLabel jlt1;
    private javax.swing.JLabel jlt2;
    private javax.swing.JLabel jltemp;
    private javax.swing.JLabel jltensao;
    private javax.swing.JMenuItem jmConectar;
    private javax.swing.JPanel jp1;
    private javax.swing.JRadioButton jrb0;
    private javax.swing.JRadioButton jrb1;
    private javax.swing.JRadioButton jrb2;
    private javax.swing.JRadioButton jrb3;
    private javax.swing.JRadioButton jrb4;
    private javax.swing.JRadioButton jrb5;
    private javax.swing.JRadioButton jrb6;
    private javax.swing.JRadioButton jrb7;
    private javax.swing.JRadioButton jrbMalhaAberta;
    private javax.swing.JRadioButton jrbMalhaFechada;
    private javax.swing.JRadioButton jrbe0;
    private javax.swing.JRadioButton jrbe1;
    private javax.swing.JRadioButton jrbe2;
    private javax.swing.JRadioButton jrbe3;
    private javax.swing.JRadioButton jrbe4;
    private javax.swing.JRadioButton jrbe5;
    private javax.swing.JRadioButton jrbe6;
    private javax.swing.JRadioButton jrbe7;
    private javax.swing.JTextArea jtLog;
    private javax.swing.JTextField jtOffSet;
    private javax.swing.JTextField jtSP;
    private javax.swing.JTextField jtServidor;
    private org.jdesktop.swingx.JXCollapsiblePane jxCollapse;
    private javax.swing.JTextField kd;
    private javax.swing.JTextField ki;
    private javax.swing.JTextField kp;
    private javax.swing.JCheckBoxMenuItem p1;
    private javax.swing.JCheckBoxMenuItem p2;
    private javax.swing.JCheckBoxMenuItem s0;
    private javax.swing.JCheckBoxMenuItem s1;
    private javax.swing.JCheckBoxMenuItem s2;
    private javax.swing.JCheckBoxMenuItem s3;
    private javax.swing.JCheckBoxMenuItem s4;
    private javax.swing.JCheckBoxMenuItem s5;
    private javax.swing.JCheckBoxMenuItem s6;
    private javax.swing.JCheckBoxMenuItem s7;
    // End of variables declaration//GEN-END:variables

    // Método para adicionar os botões no mesmo grupo, função de autoexclusão
    private void addBotoesNoGrupo() {
        group.add(jrb0);
        group.add(jrb1);
        group.add(jrb2);
        group.add(jrb3);
        group.add(jrb4);
        group.add(jrb5);
        group.add(jrb6);
        group.add(jrb7);
    }
    
    private Controlador controlador;
    
    private void inicializar(){
        zerarSelecaoSaidas();
        zerarSelecaoEntradas();
        zerarSelecaoPortas();
        
        setSaida(0, true); setEntrada(0); portaSaida = 0; portaEntrada = 0;
        setServidor("localhost"); setPorta(20081);
        setMalha(Malha.ABERTA); setSinal(); setSetPoint(20.0); setAmplitude(0.0);
        controlador.setLogInteiro(controlador.getLog().substring(0, 41) + "\n");
        jtLog.setText(controlador.getLog());
    }

    private void setSaida(int saida, boolean teste){
        zerarSelecaoSaidas();
        controlador.setSaida(saida, teste);
        
        switch(saida){
            case 0: jrb0.setSelected(true); s0.setSelected(true); break;
            case 1: jrb1.setSelected(true); s1.setSelected(true); break;
            case 2: jrb2.setSelected(true); s2.setSelected(true); break;
            case 3: jrb3.setSelected(true); s3.setSelected(true); break;
            case 4: jrb4.setSelected(true); s4.setSelected(true); break;
            case 5: jrb5.setSelected(true); s5.setSelected(true); break;
            case 6: jrb6.setSelected(true); s6.setSelected(true); break;
            case 7: jrb7.setSelected(true); s7.setSelected(true); break;
        }
        jtLog.setText(controlador.getLog());
        jtLog.setText(controlador.getLog());
    }
    
    private void zerarSelecaoSaidas() {
        jrb0.setSelected(false); s0.setSelected(false);
        jrb1.setSelected(false); s1.setSelected(false);
        jrb2.setSelected(false); s2.setSelected(false);
        jrb3.setSelected(false); s3.setSelected(false);
        jrb4.setSelected(false); s4.setSelected(false);
        jrb5.setSelected(false); s5.setSelected(false);
        jrb6.setSelected(false); s6.setSelected(false);
        jrb7.setSelected(false); s7.setSelected(false);
    }

    private void zerarSelecaoEntradas() {
        e0.setSelected(false); jrbe0.setSelected(false);
        e1.setSelected(false); jrbe1.setSelected(false);
        e2.setSelected(false); jrbe2.setSelected(false);
        e3.setSelected(false); jrbe3.setSelected(false);
        e4.setSelected(false); jrbe4.setSelected(false);
        e5.setSelected(false); jrbe5.setSelected(false);
        e6.setSelected(false); jrbe6.setSelected(false);
        e7.setSelected(false); jrbe7.setSelected(false);
    }
    
    private void zerarSelecaoPortas(){
        p1.setSelected(true);
        p2.setSelected(false);
    }

    private void setEntrada(int entrada) {
        zerarSelecaoEntradas();
        controlador.setEntrada(entrada);
        
        switch(entrada){
            case 0: e0.setSelected(true); jrbe0.setSelected(true); break;
            case 1: e1.setSelected(true); jrbe1.setSelected(true); break;
            case 2: e2.setSelected(true); jrbe2.setSelected(true); break;
            case 3: e3.setSelected(true); jrbe3.setSelected(true); break;
            case 4: e4.setSelected(true); jrbe4.setSelected(true); break;
            case 5: e5.setSelected(true); jrbe5.setSelected(true); break;
            case 6: e6.setSelected(true); jrbe6.setSelected(true); break;
            case 7: e7.setSelected(true); jrbe7.setSelected(true); break;
        }
        jtLog.setText(controlador.getLog());
    }

    private void setPorta(int porta) {
        controlador.setPorta(porta);
        if(porta == 20081){
            p1.setSelected(true);
            p2.setSelected(false);
            jcbPorta.setSelectedIndex(0);
        }else{
            p1.setSelected(false);
            p2.setSelected(true);
            jcbPorta.setSelectedIndex(1);
        }
        jtLog.setText(controlador.getLog());
    }

    private void setMalha(Malha malha) {
        controlador.setMalha(malha);
        jtLog.setText(controlador.getLog());
        
        if(malha == Malha.ABERTA){
            jrbMalhaAberta.setSelected(true);
            jrbMalhaFechada.setSelected(false);
        }else{
            jrbMalhaAberta.setSelected(false);
            jrbMalhaFechada.setSelected(true);
        }
    }

    private void setServidor(String text) {
        controlador.setServidor(text);
        jtLog.setText(controlador.getLog());
    }

    private void setDadosMalhas() {
        if(jrbMalhaAberta.isSelected()){
            setSinal();
        }else{
            controlador.setSetPoint(Double.parseDouble(jtSP.getText()));
            controlador.setKp(Double.parseDouble(kp.getText()));
            controlador.setKi(Double.parseDouble(ki.getText()));
            controlador.setKd(Double.parseDouble(kd.getText()));
            controlador.setControle(jcbControladores.getSelectedIndex());
        }
        jtLog.setText(controlador.getLog());
    }

    private void setSinal() {
        switch(jcbSinal.getSelectedIndex()){
            case 0: controlador.setSinal(Sinal.DEGRAU); break;
            case 1: controlador.setSinal(Sinal.ONDA_SENOIDAL); break;
            case 2: controlador.setSinal(Sinal.ONDA_QUADRADA); break;
            case 3: controlador.setSinal(Sinal.DENTE_DE_SERRA); break;
            case 4: controlador.setSinal(Sinal.ALEATORIO); break;
        }
        offset = Double.parseDouble(jtOffSet.getText());
        jtLog.setText(controlador.getLog());
    }

    private void conectar() {
        controlador.setLog("Tentando se conectar com o servidor "+ jtServidor.getText() + " ...");
        controlador.setServidor(jtServidor.getText());
        controlador.Conectar(jtServidor.getText());
        jtLog.setText(controlador.getLog());
        
        ActionListener action = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                try {
                    //Degrau, Senoidal, Quadrada, Dente de Serra, Aleatório
                    if (jrbMalhaAberta.isSelected() == true) {
                        malhaAberta();

                    } else if (jrbMalhaFechada.isSelected() == true) {
                        malhaFechada();
                    }

                } catch (Exception ex) {
                    System.out.println(ex);
                }
                temporizador = temporizador + 0.1;

                try {
                    //controlador.Conectar(jtServidor.getText());
                    sinal_lido = controlador.getSinalLido(portaSaida);

                    //Imprime a área de "Valores Atualizados"
                    valoresAtualizados();
                    

                }catch(Exception ex) {
                    Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(null, "Verifique a conexão!", "ERRO", 2);
                    t.stop();
                }
            }

            
        };
        t = new Timer(100, action);
        t.start();
        
        
    }
    
    private void valoresAtualizados() {
                jlsp.setText("Set-Point: " + String.format("%.2f", controlador.getSp()));
                jlt1.setText("Nível T1: " + String.format("%.2f", controlador.getNivelT1()));
                jlerro.setText("Erro: " + String.format("%.2f", controlador.getErro()));
                jltensao.setText("Tensão: " + String.format("%.2f", controlador.getTensaoMotor()));
                jltemp.setText("Temporizador: " + String.format("%.2f", temporizador));
                jlamplitude.setText("Amplitude: " + String.format("%.2f", controlador.getAmplitude()));
            }
    
    public void malhaAberta() throws QuanserClientException{
        Functions fnc = new Functions();
        double off = Double.parseDouble(jtOffSet.getText());
        SinalAbstrato SA;
        fnc.Functions(2 * Math.PI); // Periodo
        double amp = Double.parseDouble(amplitude.getValue().toString());
        jlamplitude.setText("" + amp);
        tensao = amp;
        controlador.setTensaoMotor(tensao);
        switch(controlador.getSinal()){
            case DEGRAU: 
                //tensao = fnc.Degrau(tensao, temporizador, off);
                tensao = fnc.Degrau(tensao, temporizador, offset);
                //controlador.escrever(controlador.getEntrada(), tensao);
                controlador.setTensaoMotor(tensao);
                controlador.verificarInterTravamento();
                controlador.escrever(controlador.getEntrada(), controlador.getTensaoMotor());
                plotando.addValores(controlador.getNivelT1(), 0 , controlador.getTensaoMotor(), 
                        controlador.getErro(), controlador.getSp(), controlador.getSinalLido(controlador.getSaida()));
                jltensao.setText("" + controlador.getTensaoMotor());
                valoresAtualizados();
                break;
                
            case ONDA_SENOIDAL:
                //tensao = fnc.Senoide(tensao, temporizador, off);
                tensao = fnc.Senoide2(tensao, temporizador,offset);
                //controlador.escrever(controlador.getEntrada(), tensao);
                controlador.setTensaoMotor(tensao);
                controlador.verificarInterTravamento();
                controlador.escrever(controlador.getEntrada(), controlador.getTensaoMotor());
                plotando.addValores(controlador.getNivelT1(), 0 , controlador.getTensaoMotor(), 
                        controlador.getErro(), controlador.getSp(), controlador.getSinalLido(controlador.getSaida()));
                jltensao.setText("" + controlador.getTensaoMotor());
                valoresAtualizados();
                break;
            case ONDA_QUADRADA:

                //tensao = fnc.Quadrada(tensao, temporizador, off);

                tensao = fnc.Quadrada(tensao, temporizador,offset);
                controlador.setTensaoMotor(tensao);
                controlador.verificarInterTravamento();
                controlador.escrever(controlador.getEntrada(), controlador.getTensaoMotor());
                plotando.addValores(controlador.getNivelT1(), 0 , controlador.getTensaoMotor(), 
                        controlador.getErro(), controlador.getSp(), controlador.getSinalLido(controlador.getSaida()));
                jltensao.setText("" + controlador.getTensaoMotor());
                valoresAtualizados();
                break;
            case DENTE_DE_SERRA:

                //tensao = fnc.DenteSerra(tensao, temporizador, off);

                tensao = fnc.DenteSerra(tensao, temporizador ,offset);
                controlador.escrever(controlador.getEntrada(), tensao);

                escreverMalhaAberta();
                break;
            case ALEATORIO:
                tensao = fnc.Aleatorio(tensao,offset);
                controlador.escrever(controlador.getEntrada(), tensao);
                break;
            default: jtLog.setText(controlador.getLog());
        }
        valoresAtualizados();
        plotando.addValores(controlador.getNivelT1(), 0, tensao, 
                controlador.getErro(), controlador.getSp(), sinal_lido);
    }
    
    public void malhaFechada() throws QuanserClientException {
        controlador.escrever(controlador.getEntrada(), 
                controlador.ajusteDeNivel(controlador.getSinalLido(controlador.getSaida()) * 5.5));
       
        plotando.addValores(controlador.getNivelT1(), 0, controlador.getTensaoMotor(), 
                controlador.getErro(), controlador.getSp(), controlador.getSinalLido(controlador.getSaida()));
    }
       
    private void setSetPoint(double setPoint) {
        controlador.setSetPoint(setPoint);
    }

    private void setAmplitude(double amplitude) {
        controlador.setAmplitude(amplitude);
    }
    
    private void iniciarPlot() {
        Grafico plotando = Grafico.getInstance(largura, altura);//new Grafico("Gráfico", largura, altura);
        plotando.pack();
        jPanel1.add(plotando.getContentPane());

    }
    
    public void escreverMalhaAberta() throws QuanserClientException{
        controlador.setTensaoMotor(tensao);
        controlador.verificarInterTravamento();
        controlador.escrever(controlador.getEntrada(), controlador.getTensaoMotor());
        plotando.addValores(controlador.getNivelT1(), 0 , controlador.getTensaoMotor(), 
                controlador.getErro(), controlador.getSp(), controlador.getSinalLido(controlador.getSaida()));
        jltensao.setText("" + controlador.getTensaoMotor());
        valoresAtualizados();
    }
}
